home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / unwind-prot.h < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  105 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_unwind_prot_h)
  24. #define octave_unwind_prot_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cstddef>
  31.  
  32. #include <string>
  33.  
  34. typedef void (*cleanup_func)(void *ptr);
  35.  
  36. void add_unwind_protect (cleanup_func fptr, void *ptr);
  37. void run_unwind_protect (void);
  38. void discard_unwind_protect (void);
  39. void begin_unwind_frame (const string& tag);
  40. void run_unwind_frame (const string& tag);
  41. void discard_unwind_frame (const string& tag);
  42. void run_all_unwind_protects (void);
  43. void discard_all_unwind_protects (void);
  44.  
  45. void unwind_protect_int_internal (int *ptr, int value);
  46. void unwind_protect_str_internal (string *ptr, const string& value);
  47. void unwind_protect_ptr_internal (void **ptr, void *value);
  48. void unwind_protect_var_internal (void *ptr, void *value, size_t size);
  49.  
  50. #define unwind_protect_int(i) \
  51.   unwind_protect_int_internal (&(i), (i))
  52.  
  53. #define unwind_protect_str(s) \
  54.   unwind_protect_str_internal (&(s), (s))
  55.  
  56. #define unwind_protect_ptr(p) \
  57.   unwind_protect_ptr_internal ((void **) &(p), (void *) (p))
  58.  
  59. class
  60. unwind_elem
  61. {
  62.  public:
  63.   unwind_elem (void)
  64.     : ue_tag (), ue_fptr (0), ue_ptr (0) { }
  65.  
  66.   unwind_elem (const string &t)
  67.     : ue_tag (t), ue_fptr (0), ue_ptr (0) { }
  68.  
  69.   unwind_elem (cleanup_func f, void *p)
  70.     : ue_tag (), ue_fptr (f), ue_ptr (p) { }
  71.  
  72.   unwind_elem (const unwind_elem& el)
  73.     : ue_tag (el.ue_tag), ue_fptr (el.ue_fptr), ue_ptr (el.ue_ptr) { }
  74.  
  75.   ~unwind_elem (void) { }
  76.  
  77.   unwind_elem& operator = (const unwind_elem& el)
  78.     {
  79.       ue_tag = el.ue_tag;
  80.       ue_fptr = el.ue_fptr;
  81.       ue_ptr = el.ue_ptr;
  82.  
  83.       return *this;
  84.     }
  85.  
  86.   string tag (void) { return ue_tag; }
  87.  
  88.   cleanup_func fptr (void) { return ue_fptr; }
  89.  
  90.   void *ptr (void) { return ue_ptr; }
  91.  
  92.  private:
  93.   string ue_tag;
  94.   cleanup_func ue_fptr;
  95.   void *ue_ptr;
  96. };
  97.  
  98. #endif
  99.  
  100. /*
  101. ;;; Local Variables: ***
  102. ;;; mode: C++ ***
  103. ;;; End: ***
  104. */
  105.